package com.cgwx.systemservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cgwx.springsecurity.entity.SysOperLog;
import com.cgwx.springsecurity.entity.SysOperLogQueryVo;
import com.cgwx.springsecurity.service.SysOperLogService;
import com.cgwx.systemservice.mapper.SysOperLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author GaoWei
 * @Date 2023/10/23 - 16:52
 */
@Service
public class SysOperLogServiceImpl implements SysOperLogService {
    @Autowired
    private SysOperLogMapper sysOperLogMapper;

//    操作日志记录
    @Override
    public void saveSysLog(SysOperLog operLog) {
        sysOperLogMapper.insert(operLog);
    }

//    操作日志条件分页查询
    @Override
    public IPage<SysOperLog> selectPage(Page<SysOperLog> pageParam, SysOperLogQueryVo sysOperLogQueryVo) {

        //获取条件值
        String title = sysOperLogQueryVo.getTitle();
        String operName = sysOperLogQueryVo.getOperName();
        String createTimeBegin = sysOperLogQueryVo.getCreateTimeBegin();
        String createTimeEnd = sysOperLogQueryVo.getCreateTimeEnd();

        //封装参数
        QueryWrapper<SysOperLog> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(title)) {
            wrapper.like("title",title);
        }
        if(!StringUtils.isEmpty(operName)) {
            wrapper.like("oper_name",operName);
        }
        if(!StringUtils.isEmpty(createTimeBegin)) {
            wrapper.ge("gmt_create",createTimeBegin);
        }
        if(!StringUtils.isEmpty(createTimeEnd)) {
            wrapper.le("gmt_create",createTimeEnd);
        }
        wrapper.orderByDesc("gmt_create");
        //调用mapper方法实现分页条件查询
        return sysOperLogMapper.selectPage(pageParam, wrapper);
    }
}
